from appium import webdriver
import time
from appium.webdriver.common.appiumby import By

# 连接配置信息
des = {
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}

# 实例化驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des)

# # 点击放大镜
# driver.find_element(By.ID, "com.android.settings:id/search").click()
# time.sleep(2)

# # 定位输入框元素
# set_search_input_element = driver.find_element(By.CLASS_NAME, "android.widget.EditText")
# # 输入坚果
# set_search_input_element.send_keys("坚果")
# time.sleep(2)
# # 获取元素文本内容
# print("输入【坚果】后，元素内文本值为：", set_search_input_element.text)
# # 清空
# set_search_input_element.clear()
# print("清空内容后，元素内文本值为：", set_search_input_element.text)


# 定位【使用指纹】这个元素
# element = driver.find_element(By.XPATH, "//*[@text='使用指纹']")
# # 获取id属性
# print("元素的id属性为：", element.get_attribute('resource-id'))
# # 获取class属性
# print("元素的class属性为：", element.get_attribute("class"))
# 获取元素坐标
# print("元素坐标为：", element.location)

# 获取app包名和启动名
print("当前包名：", driver.current_package)
print("当前页面名：", driver.current_activity)

time.sleep(5)
driver.quit()